home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Microsoft Multimedia Viewer How-To CD
/
Microsoft Multimedia Viewer How-To CD.iso
/
mvsample
/
progsamp
/
eplist
/
graphics.c
< prev
next >
Wrap
C/C++ Source or Header
|
1993-03-21
|
4KB
|
158 lines
#include <windows.h>
#include "graphics.h"
/************************************************************************
* MakeFont: Create a logical font using the specified hdc, typeface and
* font size.
************************************************************************/
HFONT MakeFont(HDC hdc, LPSTR lpszFace, WORD wSize)
{
PLOGFONT plf;
HFONT hfont;
plf = (PLOGFONT)LocalAlloc(GPTR, sizeof(LOGFONT));
if(plf == NULL) return NULL;
plf->lfHeight = -MulDiv(wSize, GetDeviceCaps(hdc, LOGPIXELSY), 72);
lstrcpy(plf->lfFaceName, lpszFace);
plf->lfWeight = FW_NORMAL;
hfont = CreateFontIndirect(plf);
LocalFree((LOCALHANDLE)plf);
return hfont;
}
/************************************************************************
* RectBorder: Draw a shadowed box border.
*
************************************************************************/
int RectBorder(
HDC hDC, // Where to draw border
LPRECT lprc, // Top, Left and Bottom, Right coordinates
int nWidth) // Width of bevel
{
HPEN hPen1, hPen2, hPen3, hOldPen;
HBRUSH hOldBrush;
int i;
RECT rc;
CopyRect(&rc, lprc);
hOldPen = SelectObject(hDC, GetStockObject(BLACK_PEN));
hOldBrush = SelectObject(hDC, GetStockObject(LTGRAY_BRUSH));
Rectangle(hDC, rc.left, rc.top, rc.right, rc.bottom );
rc.left += 1;
rc.top += 1;
rc.bottom -= 1;
rc.right -= 1;
// Draw top and left
hPen1 = CreatePen(PS_SOLID, 0, RGBWhite);
SelectObject(hDC, hPen1);
for (i = 0; i < nWidth; i++)
{
MoveTo(hDC, rc.left, rc.top+i);
LineTo(hDC, rc.right, rc.top+i);
MoveTo(hDC, rc.left+i, rc.top+nWidth);
LineTo(hDC, rc.left+i, rc.bottom);
}
// Draw bottom and right
hPen2 = CreatePen(PS_SOLID, 0, GetSysColor(COLOR_BTNSHADOW));
SelectObject(hDC, hPen2);
for ( i = 1; i <= nWidth; i++)
{
MoveTo(hDC, rc.left+i, rc.bottom-i);
LineTo(hDC, rc.right, rc.bottom-i);
MoveTo(hDC, rc.right-i, rc.bottom-nWidth);
LineTo(hDC, rc.right-i, rc.top+i-1);
}
hPen3 = CreatePen(PS_SOLID, 0, GetSysColor(COLOR_BTNFACE));
SelectObject(hDC, hPen3);
SelectObject(hDC, GetStockObject(LTGRAY_BRUSH));
Rectangle(hDC, rc.left+nWidth+1, rc.top+nWidth+1,
rc.right-nWidth-1, rc.bottom-nWidth-1);
SelectObject(hDC, hOldPen);
SelectObject(hDC, hOldBrush);
DeleteObject(hPen1);
DeleteObject(hPen2);
DeleteObject(hPen3);
return 0;
}
/*************************************************************************
* DrawList: Draws the text list in the specified location
*************************************************************************/
void DrawList(
HDC hdc, // Device context
int x, int y, // Origin of text list
LPRECT lprc, // Clipping rectangle
LPSTR FAR *lplist, // List to draw
int nTop, // Topmost element to draw
int nCur, // Current selection
int nList) // Count of elements in list
{
RECT rcClip;
TEXTMETRIC tm;
int iLineSpace;
int i;
SelectObject(hdc, GetStockObject(BLACK_PEN));
SelectObject(hdc, GetStockObject(WHITE_BRUSH));
SetTextColor(hdc, GetSysColor(COLOR_WINDOWTEXT));
SetBkColor(hdc, GetSysColor(COLOR_WINDOW));
GetTextMetrics(hdc, &tm);
iLineSpace = tm.tmHeight + tm.tmExternalLeading;
CopyRect(&rcClip, lprc);
for(i = nTop; i < nList && y < lprc->bottom; i++)
{
rcClip.top = y;
rcClip.bottom = min(y + iLineSpace, lprc->bottom);
if(rcClip.bottom >= lprc->top)
{
if(i == nCur)
{
SetTextColor(hdc, GetSysColor(COLOR_HIGHLIGHTTEXT));
SetBkColor(hdc, GetSysColor(COLOR_HIGHLIGHT));
}
ExtTextOut(hdc, x, y,
ETO_CLIPPED | ETO_OPAQUE, &rcClip,
lplist[i], lstrlen(lplist[i]), NULL);
if(i == nCur)
{
SetTextColor(hdc, GetSysColor(COLOR_WINDOWTEXT));
SetBkColor(hdc, GetSysColor(COLOR_WINDOW));
}
}
y += iLineSpace;
}
}